# -*- coding:utf-8 -*-
# @Time: 2020/8/25 10:34
# @Author: liupengfei
# @File: jwt.py
# from rest_framework_jwt.utils import jwt_response_payload_handler,jwt_payload_handler
from apps.account.serializers import UserJwtSerializer
from apps.member.serializers import MemberJwtSerializer, Member


def jwt_response_payload_handler(token, user=None, request=None):
    value = UserJwtSerializer(user, context={'request': request}).data
    member = Member.objects.filter(user=user)
    if not user.is_staff and member:
        value['member'] = MemberJwtSerializer(user.member, context={'request': request}).data

    return {
        'token': token,
        'user': value
    }
